package javax.core.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 常用的验证静态方法，大多返回 True/False
 */
public class RegVerifyUtil {
    public static String REG_EX_EMAIL = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
    public static String REG_EX_HAN_CHARACTER = "^[\\u4e00-\\u9fa5]{0,}$";
    public static String REG_EX_PERSON_IDENTITY = "^(\\d{6})(18|19|20)?(\\d{2})([01]\\d)([0123]\\d)(\\d{3})(\\d|X|x)?$";

    private static boolean regMatch(String input, String regEx) {
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(input);
        return matcher.matches();
    }

    /** 是否是中国手机号码**/
    public static boolean isMobilePhoneFormat(String input) {
        return false;
    }

    /** 是否是电子邮件 **/
    public static boolean isEmailFormat(String input) {
        return regMatch(input, REG_EX_EMAIL);
    }

    /** 是否是汉字 **/
    public static boolean isHanCharacter(String input) {
        return regMatch(input, REG_EX_HAN_CHARACTER);
    }

    /** 是否是身份证号码 **/
    public static boolean isPersonIdNo(String input) {
        return regMatch(input, REG_EX_PERSON_IDENTITY);
    }
}
